package com.dongdongshop.service.impl;

import com.dongdongshop.common.PageResult;
import com.dongdongshop.common.ShiroUtils;
import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@DubboService
public class TbSellerServiceImpl implements TbSellerService {
    @Resource
    private TbSellerMapper tbSellerMapper;

    @Override
    public PageResult<TbSeller> selectInfoLimitServer(TbSeller seller, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbSeller> list = tbSellerMapper.selectByNameAndNickName(seller);
        PageInfo<TbSeller> page = new PageInfo<>(list);
        PageResult<TbSeller> pageResult = new PageResult<>(page.getTotal(),page.getList());
        return pageResult;
    }

    @Override
    public TbSeller selectBySellerId(String sellerId) {
        TbSeller seller = tbSellerMapper.selectByPrimaryKey(sellerId);
        return seller;
    }

    @Override
    public int getRegisterSeller(TbSeller seller) {
        String md5 = ShiroUtils.encryptPassword("MD5", seller.getPassword(), seller.getSellerId(),3);
        seller.setPassword(md5);
        seller.setStatus("0");/*默认待审核*/
        seller.setCreateTime(new Date());/*当前时间*/
        int i = tbSellerMapper.insertSelective(seller);
        return i;
    }

    @Override
    public int getUpdateSeller(TbSeller seller) {
        int i = tbSellerMapper.updateByPrimaryKeySelective(seller);
        return i;
    }

    @Override
    public int statusSeller(TbSeller seller) {
        int i = tbSellerMapper.updateByPrimaryKeySelective(seller);
        return  i;
    }

    @Override
    public TbSeller getTbSellerBySellerId(String sellerId) {
        TbSeller seller = tbSellerMapper.selectByPrimaryKey(sellerId);
        return seller;
    }
}
